(function($,window,system){
	var basePathUrl,pathUrl;
	window.system = system;
	window.system.init = function(){
		basePathUrl = window.basePathUrl;
		pathUrl = basePathUrl + "js/prize/";
		$("#prizeCode").keyup(function(){
			if(this.value.length == 6){
				$(".prizeBtn a").addClass('on');
			}
			else{
				$(".prizeBtn a").removeClass('on');
			}
		});
		$("#prizeCode").blur(function(){
			if(this.value.length == 6){
				$(".prizeBtn a").addClass('on');
			}
			else{
				$(".prizeBtn a").removeClass('on');
			}
		});
		$(".prizeBtn a").on('click',function(){
			var code = $("#prizeCode").val();
			if(code.length == 6){				
				getGoods(code);
			}
		});
	};
	var prize = {
		Motorcycle : {id:0,text:"品牌摩托车",src:'4.png',units:'辆'},
		Iphone : {id:1,text:"iphone 7",src:'5.png',units:'台'},
		Again1 : {id:2,text:"再来一次"},
		Balance : {id:3,text:"品牌平衡车",src:'6.png',units:'辆'},
		Glove : {id:4,text:"品牌手套",src:'2.png',units:'双'},
		Electrombile : {id:5,text:"品牌电动车",src:'3.png',units:'辆'},
		Again2 : {id:6,text:"再来一次"},
		Helmet : {id:7,text:"品牌头盔",src:'1.png',units:'顶'},
	};
	var getGoods = function(code){
		var data = {prize_code:code};
		$.ajax({
			type:"get",
			url:basePathUrl+"api/wx/cash/prize",
			async:true,
			data : data,
			success : function(data){
				if(data.code == 1){
					var data = eval("("+data.data+")");
					$(".codeText").html(prize[data.dial_code].text);
					$(".view").html('<img src="'+pathUrl+'images/prize/'+prize[data.dial_code].src+'" class="single" />');
				}
				else{
					$(".codeText").html(data.mem);
					$(".view").html('<img src="'+pathUrl+'images/img-1.png" class="all" />');
				}
				$("#prizeCode").val('');
			}
		});
	};
})($,window,{});
	